# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("//p4_pdpi/testing:diff_test.bzl", "cmd_diff_test")

package(
    default_visibility = ["//visibility:public"],
    licenses = ["notice"],
)

cc_library(
    name = "p4info_helper",
    testonly = True,
    srcs = ["p4info_helper.cc"],
    hdrs = ["p4info_helper.h"],
    deps = [
        "//gutil/gutil:collections",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//thinkit:switch",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
    ],
)

cc_library(
    name = "p4rt_fixed_table_programming_helper",
    testonly = True,
    srcs = ["p4rt_fixed_table_programming_helper.cc"],
    hdrs = ["p4rt_fixed_table_programming_helper.h"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//sai_p4/instantiations/google/test_tools:test_entries", 
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "p4rt_fixed_table_programming_helper_test",
    srcs = ["p4rt_fixed_table_programming_helper_test.cc"],
    deps = [
        ":p4rt_fixed_table_programming_helper",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "common_ir_table_entries",
    testonly = True,
    srcs = ["common_ir_table_entries.cc"],
    hdrs = ["common_ir_table_entries.h"],
    deps = [
        "//p4_pdpi:ir_cc_proto",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "common_ir_table_entries_test",
    srcs = ["common_ir_table_entries_test.cc"],
    deps = [
        ":common_ir_table_entries",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi:ir",
        "//p4_pdpi:ir_cc_proto",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "switch_test_setup_helpers",
    testonly = True,
    srcs = ["switch_test_setup_helpers.cc"],
    hdrs = ["switch_test_setup_helpers.h"],
    deps = [
        "//gutil/gutil:collections",
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//lib/gnmi:gnmi_helper",
        "//lib/gnmi:openconfig_cc_proto",
        "//lib/p4rt:p4rt_port",
        "//lib/validator:validator_lib",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:ir_tools",
        "//p4_pdpi:p4_runtime_session",
        "//tests:thinkit_sanity_tests",
        "//thinkit:mirror_testbed",
        "//thinkit:switch",
        "@com_github_gnmi//proto/gnmi:gnmi_cc_grpc_proto",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4info_cc_proto",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_github_p4lang_p4runtime//:p4types_cc_proto",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:span",
        "@com_google_googletest//:gtest",
    ],
)

# go/golden-test-with-coverage
cc_test(
    name = "switch_test_setup_helpers_golden_test_runner",
    srcs = ["switch_test_setup_helpers_golden_test_runner.cc"],
    data = ["switch_test_setup_helpers.expected"],
    linkstatic = True,
    deps = [
        ":switch_test_setup_helpers",
        "//gutil/gutil:proto",
        "//gutil/gutil:status_matchers",
        "//gutil/gutil:testing",
        "//lib/p4rt:p4rt_port",
        "//p4_pdpi:ir_cc_proto",
        "//sai_p4/instantiations/google:instantiations",
        "//sai_p4/instantiations/google:sai_p4info_cc",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/types:span",
        "@com_google_protobuf//:protobuf",
    ],
)

cmd_diff_test(
    name = "switch_test_setup_helpers_golden_test",
    actual_cmd = "$(execpath :switch_test_setup_helpers_golden_test_runner)",
    expected = "//tests/lib:switch_test_setup_helpers.expected",
    tools = [
        ":switch_test_setup_helpers_golden_test_runner",
    ],
)

cc_library(
    name = "packet_in_helper",
    srcs = ["packet_in_helper.cc"],
    hdrs = ["packet_in_helper.h"],
    deps = [
        "//p4_pdpi:p4_runtime_session",
        "@com_github_google_glog//:glog",
        "@com_github_p4lang_p4runtime//:p4runtime_cc_proto",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/synchronization",
    ],
)

cc_library(
    name = "packet_generator",
    testonly = True,
    srcs = ["packet_generator.cc"],
    hdrs = ["packet_generator.h"],
    deps = [
        "//gutil/gutil:proto",
        "//gutil/gutil:status",
        "//p4_pdpi/netaddr:ipv4_address",
        "//p4_pdpi/netaddr:ipv6_address",
        "//p4_pdpi/netaddr:mac_address",
        "//p4_pdpi/packetlib",
        "//p4_pdpi/packetlib:bit_widths",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/numeric:int128",
        "@com_google_absl//absl/random:distributions",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_test(
    name = "packet_generator_test",
    srcs = ["packet_generator_test.cc"],
    shard_count = 4,
    deps = [
        ":packet_generator",
        "//gutil/gutil:proto_matchers",
        "//gutil/gutil:status_matchers",
        "//p4_pdpi/packetlib",
        "//p4_pdpi/packetlib:packetlib_cc_proto",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "packet_injector",
    testonly = True,
    srcs = ["packet_injector.cc"],
    hdrs = ["packet_injector.h"],
    deps = [
        "//lib/p4rt:p4rt_port",
        "//p4_pdpi:ir_cc_proto",
        "//p4_pdpi:p4_runtime_session",
        "//tests/forwarding:util",
        "@com_github_google_glog//:glog",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/functional:any_invocable",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/synchronization",
        "@com_google_absl//absl/time",
    ],
)
